package com.timesheet.gui.efforttracker.controllers;

import com.timesheet.gui.efforttracker.actions.DeleteEffortAction;
import com.timesheet.gui.efforttracker.actions.EditEffortAction;
import com.timesheet.gui.efforttracker.actions.UpdateEffortAction;
import com.timesheet.gui.efforttracker.composite.NewEffortResultTableComposite;
import com.timesheet.gui.efforttracker.composite.SectionEffortComposite;

import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.forms.widgets.Section;

public class SectionEffortCompositeController {

	private SectionEffortComposite sectionEffortComposite = null;

	public SectionEffortCompositeController(SectionEffortComposite sectionEffortComposite) {
		this.sectionEffortComposite = sectionEffortComposite;
		createActions();
	}

	/**
	 * 
	 */
	private void createActions() {
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
		Section sectionSavedEffort = sectionEffortComposite.getSectionSavedEffort();
		ToolBar toolbar = toolBarManager.createControl(sectionSavedEffort);
		UpdateEffortAction updateEffortAction = new UpdateEffortAction(this);
		DeleteEffortAction delteEffortAction = new DeleteEffortAction(this);
		EditEffortAction editEffortAction = new EditEffortAction(this);
		toolBarManager.add(editEffortAction);
		toolBarManager.add(delteEffortAction);
		toolBarManager.add(updateEffortAction);
		toolBarManager.update(true);
		sectionSavedEffort.setTextClient(toolbar);
	}

	public NewEffortResultTableComposite getNewEffortResultTableComposite() {
		NewEffortResultTableComposite newEffortResultTableComposite =
				sectionEffortComposite.getNewEffortResultTableComposite();
		return newEffortResultTableComposite;
	}
}
